#include "Main/stdafx.h"
#include "BRNNGameScence.h"
#include "Game/GameLib.h"
#include "BRNNPlayer.h"

BRNNPlayer* BRNNGameScence::getPlayerByChairID(int iChairID)
{
	if (!m_pLocal->getUserItem(false))
	{
		return m_pLocal;
	}

	int nPos = m_pLocal->GetChairID();
	if (nPos == iChairID)
		return m_pLocal;

	int iIdex = (m_pLocal->GetChairID()-iChairID+MAX_PLAYER)%MAX_PLAYER;
	return m_pPlayer[iIdex];
}

BRNNPlayer* BRNNGameScence::getPlayerByUserId(int userId)
{
	if (!m_pLocal->getUserItem(false))
	{
		return m_pLocal;
	}

	for (int i = 0; i < MAX_PLAYER; ++i)
	{
		if (m_pPlayer[i]->checkUserSitDown() && m_pPlayer[i]->GetUserID() == userId)
			return m_pPlayer[i];
	}
	return NULL;
}

GamePlayer* BRNNGameScence::CreatePlayer( IClientUserItem * pIClientUserItem )
{
	if (pIClientUserItem->GetUserID() == UserInfo::Instance().getUserID())
	{
		m_pLocal->setUserItem(pIClientUserItem);
		return m_pLocal;
	}
	else
	{
		GamePlayer* pPlayer = getPlayerByChairID(pIClientUserItem->GetChairID());
		pPlayer->setUserItem(pIClientUserItem);
		return pPlayer;
	}
	return NULL;
}
void BRNNGameScence::DeletePlayer(GamePlayer* pPlayer)
{
}
void BRNNGameScence::upSelfPlayerInfo()
{
	Node* uInfo = (Node*)_layout->getChildByName("Sprite_bottom");
	Text* nickName = (Text*)uInfo->getChildByName("Text_selfName");
	if (nickName)
		nickName->setString(getSelfGamePlayer()->GetNickName());

	//Text* sMoney = (Text*)_layout->getChildByName("selfMoney");
	//sMoney->setString(StringUtils::format("%d", getSelfGamePlayer()->GetUserScore()));
}
